<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <%@ include file="/static/admin/jsp/include.jsp"%>
    <style type="text/css">
        .textbox.textbox-focused .textbox-addon,
        .textbox.textbox-focused .textbox-text{
            background: #eee!important;
        }
    </style>
    <script type="text/javascript">
        var id = "${id}";


        submitForm = function($dialog, $grid, $pjq) {
            if ($('form').form('validate')) {
                var obj=sy.serializeObject($('form'));
                var url=sy.contextPath + '/chemicalType/save';
                var type = $("#type").combobox("getValue");
                if(type == 1){
                    obj.rangeInfo = $("#rangeInfos").combobox("getValue");
                }else if(type == 2){

                    obj.rangeInfo = $("#rangeInfo").textbox("getValue");
                }
                obj.type = $("#type").combobox("getValue");
                obj.info = editor.getHtml();
                //判断名称是否有重复的
                parent.$.messager.confirm('询问', '确定保存？', function(r) {
                    if (r) {
                        $.post(url, obj, function(result) {
                            if (result.code == 0) {
                                parent.$.messager.i('保存成功');
                                $grid.datagrid('reload');
                                $dialog.dialog('destroy');
                            } else {
                                $pjq.messager.e('保存失败,'+result.msg);
                            }
                        }, 'json');
                    }
                });




            }
        };

        $(function() {
            editor = new HtmlEditor('#info');
            $("#rangeParam").hide();
            $("#rangeParam1").hide();
            $("#rangeParam2").show();
            $("#type").combobox({
                onChange: function (newValue, oldValue) {
                    if(newValue == 1){
                        //阴阳
                        $("#rangeParam").hide();
                        $("#rangeParam1").hide();
                        $("#rangeParam2").show();
                    }else if(newValue == 2){
                        //数值
                        $("#rangeParam2").hide();
                        $("#rangeParam").show();
                        $("#rangeParam1").show();
                    }

                }

            });

            if(id != ''){
                $.post(sy.contextPath + '/chemicalType/findById', {
                    id : id,
                }, function(result) {
                    if (id != '') {
                        parent.$.messager.progress({
                            text : '数据加载中....'
                        });
                        $.post(sy.contextPath + '/chemicalType/findById', {
                            id : id
                        }, function(result) {
                            console.log(result)
                            if (result) {
                                editor.setHtml(result.info).readonly();
                                $('form').form('load', result);
                            }
                            parent.$.messager.progress('close');
                        }, 'json');

                    }
                })
            }
        });

    </script>
</head>
<body>
<form id="form" method="post">
    <input name="id" type="hidden" />
    <div style="padding:15px;font-size: 12px">
        <table style="table-layout:fixed;" border="0" cellspacing="0" class="formtable">

            <tr>
                <th style="width:100px;">释义：</th>
                <td colspan="3">
                    <textarea id="info" style="width:80%;height: 300px" readonly="readonly"></textarea>
                </td>
            </tr>

        </table>
    </div>
</form>
</body>
</html>